package com.CNMedical.system.service.impl;

import java.util.List;

import com.diboot.core.binding.Binder;
import com.diboot.core.service.impl.BaseServiceImpl;
import com.CNMedical.common.utils.DateUtils;
import com.CNMedical.system.domain.vo.AppletQuestionOptionVO;
import org.springframework.stereotype.Service;
import com.CNMedical.system.mapper.AppletQuestionOptionMapper;
import com.CNMedical.system.domain.entity.AppletQuestionOption;
import com.CNMedical.system.service.IAppletQuestionOptionService;

import javax.annotation.Resource;

/**
 * 试题选项Service业务层处理
 * 
 * @author tang
 * @date 2023-03-28
 */
@Service
public class AppletQuestionOptionServiceImpl extends BaseServiceImpl<AppletQuestionOptionMapper, AppletQuestionOption> implements IAppletQuestionOptionService
{
    @Resource
    private AppletQuestionOptionMapper appletQuestionOptionMapper;

    @Override
    public String whetherCorrectOption(String questionId, String optionId) {
        return lambdaQuery().eq(AppletQuestionOption::getId, optionId)
                .eq(AppletQuestionOption::getQuestionId, questionId).one().getCorrect();
    }

    @Override
    public List<AppletQuestionOption> getAllOptionsByQuestionId(String questionId) {
        return lambdaQuery().eq(AppletQuestionOption::getQuestionId,questionId).list();
    }

    /**
     * 查询试题选项
     * 
     * @param id 试题选项主键
     * @return 试题选项
     */
    @Override
    public AppletQuestionOption selectAppletQuestionOptionById(Long id)
    {
        return appletQuestionOptionMapper.selectAppletQuestionOptionById(id);
    }

    /**
     * 查询试题选项列表
     * 
     * @param appletQuestionOption 试题选项
     * @return 试题选项
     */
    @Override
    public List<AppletQuestionOptionVO> selectAppletQuestionOptionList(AppletQuestionOption appletQuestionOption)
    {
        List<AppletQuestionOption> appletQuestionOptions = appletQuestionOptionMapper.selectAppletQuestionOptionList(appletQuestionOption);
        List<AppletQuestionOptionVO> appletQuestionOptionVOS = Binder.convertAndBindRelations(appletQuestionOptions, AppletQuestionOptionVO.class);
        return appletQuestionOptionVOS;
    }

    /**
     * 新增试题选项
     * 
     * @param appletQuestionOption 试题选项
     * @return 结果
     */
    @Override
    public int insertAppletQuestionOption(AppletQuestionOption appletQuestionOption)
    {
        appletQuestionOption.setCreateTime(DateUtils.getNowDate());
        return appletQuestionOptionMapper.insertAppletQuestionOption(appletQuestionOption);
    }

    /**
     * 修改试题选项
     * 
     * @param appletQuestionOption 试题选项
     * @return 结果
     */
    @Override
    public int updateAppletQuestionOption(AppletQuestionOption appletQuestionOption)
    {
        appletQuestionOption.setUpdateTime(DateUtils.getNowDate());
        return appletQuestionOptionMapper.updateAppletQuestionOption(appletQuestionOption);
    }

    /**
     * 批量删除试题选项
     * 
     * @param ids 需要删除的试题选项主键
     * @return 结果
     */
    @Override
    public int deleteAppletQuestionOptionByIds(Long[] ids)
    {
        return appletQuestionOptionMapper.deleteAppletQuestionOptionByIds(ids);
    }

    /**
     * 删除试题选项信息
     * 
     * @param id 试题选项主键
     * @return 结果
     */
    @Override
    public int deleteAppletQuestionOptionById(Long id)
    {
        return appletQuestionOptionMapper.deleteAppletQuestionOptionById(id);
    }
}
